package com.mew.common.dc.redis;

import com.mew.common.config.FishRedisValue;
import com.mew.common.config.RedisConstantValue;
import com.mew.common.entity.config.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class FishingRedisService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public List<FishingFish> findFish(){
        List<Object> list =  redisTemplate.opsForList().range(RedisConstantValue.CONFIG_FISHING_FISH, 0, -1);
        return list.stream().map(o -> (FishingFish)o).collect(Collectors.toList());
    }

    public FishRedisValue fishCongfig(){
        FishRedisValue fishRedisValue = (FishRedisValue) redisTemplate.opsForValue().get(RedisConstantValue.CONFIG_FISHING_CONFIG);
        if (null==fishRedisValue){
            fishRedisValue = new FishRedisValue();
            redisTemplate.opsForValue().set(RedisConstantValue.CONFIG_FISHING_CONFIG,fishRedisValue);
            return fishRedisValue;
        }

        return fishRedisValue;
    }

    public List<FishingQmcs> findQmcs(){
        List<Object> list =  redisTemplate.opsForList().range(RedisConstantValue.CONFIG_FISHING_QMCS, 0, -1);
        return list.stream().map(o -> (FishingQmcs)o).collect(Collectors.toList());
    }

}
